package com.strelitzia.controller;

import com.strelitzia.entity.AlbumEntity;
import com.strelitzia.service.AlbumService;
import com.strelitzia.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @create 2024/1/12 13:54
 */
@RestController
@RequestMapping("/album")
public class AlbumController {
    @Autowired
    private AlbumService albumService;

    @PostMapping()
    public ResultVo create(String name) {
        ResultVo resultVo = new ResultVo();
        try {
            albumService.create(name);
            resultVo.setMsg("创建成功");
        } catch (Exception e) {
            resultVo.setCode(1);
            resultVo.setMsg("创建失败");
        }
        return resultVo;
    }

    @GetMapping("/list/{type}")
    public ResultVo list(@PathVariable("type") Integer type) {
        ResultVo resultVo = new ResultVo();
        try {
            resultVo.setData(albumService.getList(type));
        } catch (Exception e) {
            resultVo.setCode(1);
            resultVo.setMsg("服务器错误");
        }
        return resultVo;
    }

    @GetMapping("/list/friend/{id}")
    public ResultVo fList(@PathVariable("id") Integer id) {
        ResultVo resultVo = new ResultVo();
        try {
            resultVo.setData(albumService.getFriendList(id));
        } catch (Exception e) {
            resultVo.setCode(1);
            resultVo.setMsg("服务器错误");
        }
        return resultVo;
    }

    @GetMapping("/del/{id}")
    public ResultVo del(@PathVariable("id") Integer id) {
        ResultVo resultVo = new ResultVo();
        try {
            albumService.del(id);
            resultVo.setMsg("删除成功");
        } catch (Exception e) {
            resultVo.setCode(1);
            resultVo.setMsg("服务器错误");
        }
        return resultVo;
    }

    @GetMapping("/status/{id}/{status}")
    public void status(@PathVariable("id") Integer id, @PathVariable("status") Integer status) {
        AlbumEntity albumEntity = new AlbumEntity();
        albumEntity.setId(id);
        albumEntity.setStatus(status);
        this.albumService.updateById(albumEntity);
    }


}
